
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Vue实例挂载的实现 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="render.html" />
    
    
    <link rel="prev" href="new-vue.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../prepare/">
            
                <a href="../prepare/">
            
                    
                    准备工作
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../prepare/flow.html">
            
                <a href="../prepare/flow.html">
            
                    
                    认识flow
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../prepare/directory.html">
            
                <a href="../prepare/directory.html">
            
                    
                    Vue.js源码目录设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../prepare/build.html">
            
                <a href="../prepare/build.html">
            
                    
                    Vue.js源码构建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../prepare/entrance.html">
            
                <a href="../prepare/entrance.html">
            
                    
                    从入口开始
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="./">
            
                <a href="./">
            
                    
                    数据驱动
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="./">
            
                <a href="./">
            
                    
                    数据驱动
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="new-vue.html">
            
                <a href="new-vue.html">
            
                    
                    new Vue发生了什么
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.3" data-path="mounted.html">
            
                <a href="mounted.html">
            
                    
                    Vue实例挂载的实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="render.html">
            
                <a href="render.html">
            
                    
                    render
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="virtual-dom.html">
            
                <a href="virtual-dom.html">
            
                    
                    Visual Dom
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="create-element.html">
            
                <a href="create-element.html">
            
                    
                    createElement
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="update.html">
            
                <a href="update.html">
            
                    
                    update
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >Vue实例挂载的实现</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="vue-&#x5B9E;&#x4F8B;&#x6302;&#x8F7D;&#x7684;&#x5B9E;&#x73B0;">Vue &#x5B9E;&#x4F8B;&#x6302;&#x8F7D;&#x7684;&#x5B9E;&#x73B0;</h1>
<p>Vue &#x4E2D;&#x6211;&#x4EEC;&#x662F;&#x901A;&#x8FC7; <code>$mount</code> &#x5B9E;&#x4F8B;&#x65B9;&#x6CD5;&#x53BB;&#x6302;&#x8F7D; <code>vm</code> &#x7684;&#xFF0C;<code>$mount</code> &#x65B9;&#x6CD5;&#x5728;&#x591A;&#x4E2A;&#x6587;&#x4EF6;&#x4E2D;&#x90FD;&#x6709;&#x5B9A;&#x4E49;&#xFF0C;&#x5982; <code>src/platform/web/entry-runtime-with-compiler.js</code>&#x3001;<code>src/platform/web/runtime/index.js</code>&#x3001;<code>src/platform/weex/runtime/index.js</code>&#x3002;&#x56E0;&#x4E3A; <code>$mount</code> &#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x7684;&#x5B9E;&#x73B0;&#x662F;&#x548C;&#x5E73;&#x53F0;&#x3001;&#x6784;&#x5EFA;&#x65B9;&#x5F0F;&#x90FD;&#x76F8;&#x5173;&#x7684;&#x3002;&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x91CD;&#x70B9;&#x5206;&#x6790;&#x5E26; <code>compiler</code> &#x7248;&#x672C;&#x7684; <code>$mount</code> &#x5B9E;&#x73B0;&#xFF0C;&#x56E0;&#x4E3A;&#x629B;&#x5F00; webpack &#x7684; vue-loader&#xFF0C;&#x6211;&#x4EEC;&#x5728;&#x7EAF;&#x524D;&#x7AEF;&#x6D4F;&#x89C8;&#x5668;&#x73AF;&#x5883;&#x5206;&#x6790; Vue &#x7684;&#x5DE5;&#x4F5C;&#x539F;&#x7406;&#xFF0C;&#x6709;&#x52A9;&#x4E8E;&#x6211;&#x4EEC;&#x5BF9;&#x539F;&#x7406;&#x7406;&#x89E3;&#x7684;&#x6DF1;&#x5165;&#x3002;</p>
<p><code>compiler</code> &#x7248;&#x672C;&#x7684; <code>$mount</code> &#x5B9E;&#x73B0;&#x975E;&#x5E38;&#x6709;&#x610F;&#x601D;&#xFF0C;&#x5148;&#x6765;&#x770B;&#x4E00;&#x4E0B; <code>src/platform/web/entry-runtime-with-compiler.js</code> &#x6587;&#x4EF6;&#x4E2D;&#x5B9A;&#x4E49;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> mount = Vue.prototype.$mount
Vue.prototype.$mount = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">
  el?: string | Element,
  hydrating?: boolean
</span>): <span class="hljs-title">Component</span> </span>{
  el = el &amp;&amp; query(el)

  <span class="hljs-comment">/* istanbul ignore if */</span>
  <span class="hljs-keyword">if</span> (el === <span class="hljs-built_in">document</span>.body || el === <span class="hljs-built_in">document</span>.documentElement) {
    process.env.NODE_ENV !== <span class="hljs-string">&apos;production&apos;</span> &amp;&amp; warn(
      <span class="hljs-string">`Do not mount Vue to &lt;html&gt; or &lt;body&gt; - mount to normal elements instead.`</span>
    )
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>
  }

  <span class="hljs-keyword">const</span> options = <span class="hljs-keyword">this</span>.$options
  <span class="hljs-comment">// resolve template/el and convert to render function</span>
  <span class="hljs-keyword">if</span> (!options.render) {
    <span class="hljs-keyword">let</span> template = options.template
    <span class="hljs-keyword">if</span> (template) {
      <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> template === <span class="hljs-string">&apos;string&apos;</span>) {
        <span class="hljs-keyword">if</span> (template.charAt(<span class="hljs-number">0</span>) === <span class="hljs-string">&apos;#&apos;</span>) {
          template = idToTemplate(template)
          <span class="hljs-comment">/* istanbul ignore if */</span>
          <span class="hljs-keyword">if</span> (process.env.NODE_ENV !== <span class="hljs-string">&apos;production&apos;</span> &amp;&amp; !template) {
            warn(
              <span class="hljs-string">`Template element not found or is empty: <span class="hljs-subst">${options.template}</span>`</span>,
              <span class="hljs-keyword">this</span>
            )
          }
        }
      } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (template.nodeType) {
        template = template.innerHTML
      } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">if</span> (process.env.NODE_ENV !== <span class="hljs-string">&apos;production&apos;</span>) {
          warn(<span class="hljs-string">&apos;invalid template option:&apos;</span> + template, <span class="hljs-keyword">this</span>)
        }
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>
      }
    } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (el) {
      template = getOuterHTML(el)
    }
    <span class="hljs-keyword">if</span> (template) {
      <span class="hljs-comment">/* istanbul ignore if */</span>
      <span class="hljs-keyword">if</span> (process.env.NODE_ENV !== <span class="hljs-string">&apos;production&apos;</span> &amp;&amp; config.performance &amp;&amp; mark) {
        mark(<span class="hljs-string">&apos;compile&apos;</span>)
      }

      <span class="hljs-keyword">const</span> { render, staticRenderFns } = compileToFunctions(template, {
        shouldDecodeNewlines,
        shouldDecodeNewlinesForHref,
        delimiters: options.delimiters,
        comments: options.comments
      }, <span class="hljs-keyword">this</span>)
      options.render = render
      options.staticRenderFns = staticRenderFns

      <span class="hljs-comment">/* istanbul ignore if */</span>
      <span class="hljs-keyword">if</span> (process.env.NODE_ENV !== <span class="hljs-string">&apos;production&apos;</span> &amp;&amp; config.performance &amp;&amp; mark) {
        mark(<span class="hljs-string">&apos;compile end&apos;</span>)
        measure(<span class="hljs-string">`vue <span class="hljs-subst">${this._name}</span> compile`</span>, <span class="hljs-string">&apos;compile&apos;</span>, <span class="hljs-string">&apos;compile end&apos;</span>)
      }
    }
  }
  <span class="hljs-keyword">return</span> mount.call(<span class="hljs-keyword">this</span>, el, hydrating)
}
</code></pre>
<p>&#x8FD9;&#x6BB5;&#x4EE3;&#x7801;&#x9996;&#x5148;&#x7F13;&#x5B58;&#x4E86;&#x539F;&#x578B;&#x4E0A;&#x7684; <code>$mount</code> &#x65B9;&#x6CD5;&#xFF0C;&#x518D;&#x91CD;&#x65B0;&#x5B9A;&#x4E49;&#x8BE5;&#x65B9;&#x6CD5;&#xFF0C;&#x6211;&#x4EEC;&#x5148;&#x6765;&#x5206;&#x6790;&#x8FD9;&#x6BB5;&#x4EE3;&#x7801;&#x3002;&#x9996;&#x5148;&#xFF0C;&#x5B83;&#x5BF9; <code>el</code> &#x505A;&#x4E86;&#x9650;&#x5236;&#xFF0C;Vue &#x4E0D;&#x80FD;&#x6302;&#x8F7D;&#x5728; <code>body</code>&#x3001;<code>html</code> &#x8FD9;&#x6837;&#x7684;&#x6839;&#x8282;&#x70B9;&#x4E0A;&#x3002;&#x63A5;&#x4E0B;&#x6765;&#x7684;&#x662F;&#x5F88;&#x5173;&#x952E;&#x7684;&#x903B;&#x8F91; &#x2014;&#x2014; &#x5982;&#x679C;&#x6CA1;&#x6709;&#x5B9A;&#x4E49; <code>render</code> &#x65B9;&#x6CD5;&#xFF0C;&#x5219;&#x4F1A;&#x628A; <code>el</code> &#x6216;&#x8005; <code>template</code> &#x5B57;&#x7B26;&#x4E32;&#x8F6C;&#x6362;&#x6210; <code>render</code> &#x65B9;&#x6CD5;&#x3002;&#x8FD9;&#x91CC;&#x6211;&#x4EEC;&#x8981;&#x7262;&#x8BB0;&#xFF0C;&#x5728; Vue 2.0 &#x7248;&#x672C;&#x4E2D;&#xFF0C;&#x6240;&#x6709; Vue &#x7684;&#x7EC4;&#x4EF6;&#x7684;&#x6E32;&#x67D3;&#x6700;&#x7EC8;&#x90FD;&#x9700;&#x8981; <code>render</code> &#x65B9;&#x6CD5;&#xFF0C;&#x65E0;&#x8BBA;&#x6211;&#x4EEC;&#x662F;&#x7528;&#x5355;&#x6587;&#x4EF6; .vue &#x65B9;&#x5F0F;&#x5F00;&#x53D1;&#x7EC4;&#x4EF6;&#xFF0C;&#x8FD8;&#x662F;&#x5199;&#x4E86; <code>el</code> &#x6216;&#x8005; <code>template</code> &#x5C5E;&#x6027;&#xFF0C;&#x6700;&#x7EC8;&#x90FD;&#x4F1A;&#x8F6C;&#x6362;&#x6210; <code>render</code> &#x65B9;&#x6CD5;&#xFF0C;&#x90A3;&#x4E48;&#x8FD9;&#x4E2A;&#x8FC7;&#x7A0B;&#x662F; Vue &#x7684;&#x4E00;&#x4E2A;&#x201C;&#x5728;&#x7EBF;&#x7F16;&#x8BD1;&#x201D;&#x7684;&#x8FC7;&#x7A0B;&#xFF0C;&#x5B83;&#x662F;&#x8C03;&#x7528; <code>compileToFunctions</code> &#x65B9;&#x6CD5;&#x5B9E;&#x73B0;&#x7684;&#xFF0C;&#x7F16;&#x8BD1;&#x8FC7;&#x7A0B;&#x6211;&#x4EEC;&#x4E4B;&#x540E;&#x4F1A;&#x4ECB;&#x7ECD;&#x3002;&#x6700;&#x540E;&#xFF0C;&#x8C03;&#x7528;&#x539F;&#x5148;&#x539F;&#x578B;&#x4E0A;&#x7684; <code>$mount</code> &#x65B9;&#x6CD5;&#x6302;&#x8F7D;&#x3002;</p>
<p>&#x539F;&#x5148;&#x539F;&#x578B;&#x4E0A;&#x7684; <code>$mount</code> &#x65B9;&#x6CD5;&#x5728; <code>src/platform/web/runtime/index.js</code> &#x4E2D;&#x5B9A;&#x4E49;&#xFF0C;&#x4E4B;&#x6240;&#x4EE5;&#x8FD9;&#x4E48;&#x8BBE;&#x8BA1;&#x5B8C;&#x5168;&#x662F;&#x4E3A;&#x4E86;&#x590D;&#x7528;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x662F;&#x53EF;&#x4EE5;&#x88AB; <code>runtime only</code> &#x7248;&#x672C;&#x7684; Vue &#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x7684;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-comment">// public mount method</span>
Vue.prototype.$mount = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">
  el?: string | Element,
  hydrating?: boolean
</span>): <span class="hljs-title">Component</span> </span>{
  el = el &amp;&amp; inBrowser ? query(el) : <span class="hljs-literal">undefined</span>
  <span class="hljs-keyword">return</span> mountComponent(<span class="hljs-keyword">this</span>, el, hydrating)
}
</code></pre>
<p><code>$mount</code> &#x65B9;&#x6CD5;&#x652F;&#x6301;&#x4F20;&#x5165; 2 &#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x7B2C;&#x4E00;&#x4E2A;&#x662F; <code>el</code>&#xFF0C;&#x5B83;&#x8868;&#x793A;&#x6302;&#x8F7D;&#x7684;&#x5143;&#x7D20;&#xFF0C;&#x53EF;&#x4EE5;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x662F; DOM &#x5BF9;&#x8C61;&#xFF0C;&#x5982;&#x679C;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x73AF;&#x5883;&#x4E0B;&#x4F1A;&#x8C03;&#x7528; <code>query</code> &#x65B9;&#x6CD5;&#x8F6C;&#x6362;&#x6210; DOM &#x5BF9;&#x8C61;&#x7684;&#x3002;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x548C;&#x670D;&#x52A1;&#x7AEF;&#x6E32;&#x67D3;&#x76F8;&#x5173;&#xFF0C;&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x73AF;&#x5883;&#x4E0B;&#x6211;&#x4EEC;&#x4E0D;&#x9700;&#x8981;&#x4F20;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x3002;</p>
<p><code>$mount</code> &#x65B9;&#x6CD5;&#x5B9E;&#x9645;&#x4E0A;&#x4F1A;&#x53BB;&#x8C03;&#x7528; <code>mountComponent</code> &#x65B9;&#x6CD5;&#xFF0C;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x5B9A;&#x4E49;&#x5728; <code>src/core/instance/lifecycle.js</code> &#x6587;&#x4EF6;&#x4E2D;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mountComponent</span> (<span class="hljs-params">
  vm: Component,
  el: ?Element,
  hydrating?: boolean
</span>): <span class="hljs-title">Component</span> </span>{
  vm.$el = el
  <span class="hljs-keyword">if</span> (!vm.$options.render) {
    vm.$options.render = createEmptyVNode
    <span class="hljs-keyword">if</span> (process.env.NODE_ENV !== <span class="hljs-string">&apos;production&apos;</span>) {
      <span class="hljs-comment">/* istanbul ignore if */</span>
      <span class="hljs-keyword">if</span> ((vm.$options.template &amp;&amp; vm.$options.template.charAt(<span class="hljs-number">0</span>) !== <span class="hljs-string">&apos;#&apos;</span>) ||
        vm.$options.el || el) {
        warn(
          <span class="hljs-string">&apos;You are using the runtime-only build of Vue where the template &apos;</span> +
          <span class="hljs-string">&apos;compiler is not available. Either pre-compile the templates into &apos;</span> +
          <span class="hljs-string">&apos;render functions, or use the compiler-included build.&apos;</span>,
          vm
        )
      } <span class="hljs-keyword">else</span> {
        warn(
          <span class="hljs-string">&apos;Failed to mount component: template or render function not defined.&apos;</span>,
          vm
        )
      }
    }
  }
  callHook(vm, <span class="hljs-string">&apos;beforeMount&apos;</span>)

  <span class="hljs-keyword">let</span> updateComponent
  <span class="hljs-comment">/* istanbul ignore if */</span>
  <span class="hljs-keyword">if</span> (process.env.NODE_ENV !== <span class="hljs-string">&apos;production&apos;</span> &amp;&amp; config.performance &amp;&amp; mark) {
    updateComponent = () =&gt; {
      <span class="hljs-keyword">const</span> name = vm._name
      <span class="hljs-keyword">const</span> id = vm._uid
      <span class="hljs-keyword">const</span> startTag = <span class="hljs-string">`vue-perf-start:<span class="hljs-subst">${id}</span>`</span>
      <span class="hljs-keyword">const</span> endTag = <span class="hljs-string">`vue-perf-end:<span class="hljs-subst">${id}</span>`</span>

      mark(startTag)
      <span class="hljs-keyword">const</span> vnode = vm._render()
      mark(endTag)
      measure(<span class="hljs-string">`vue <span class="hljs-subst">${name}</span> render`</span>, startTag, endTag)

      mark(startTag)
      vm._update(vnode, hydrating)
      mark(endTag)
      measure(<span class="hljs-string">`vue <span class="hljs-subst">${name}</span> patch`</span>, startTag, endTag)
    }
  } <span class="hljs-keyword">else</span> {
    updateComponent = () =&gt; {
      vm._update(vm._render(), hydrating)
    }
  }

  <span class="hljs-comment">// we set this to vm._watcher inside the watcher&apos;s constructor</span>
  <span class="hljs-comment">// since the watcher&apos;s initial patch may call $forceUpdate (e.g. inside child</span>
  <span class="hljs-comment">// component&apos;s mounted hook), which relies on vm._watcher being already defined</span>
  <span class="hljs-keyword">new</span> Watcher(vm, updateComponent, noop, {
    before () {
      <span class="hljs-keyword">if</span> (vm._isMounted) {
        callHook(vm, <span class="hljs-string">&apos;beforeUpdate&apos;</span>)
      }
    }
  }, <span class="hljs-literal">true</span> <span class="hljs-comment">/* isRenderWatcher */</span>)
  hydrating = <span class="hljs-literal">false</span>

  <span class="hljs-comment">// manually mounted instance, call mounted on self</span>
  <span class="hljs-comment">// mounted is called for render-created child components in its inserted hook</span>
  <span class="hljs-keyword">if</span> (vm.$vnode == <span class="hljs-literal">null</span>) {
    vm._isMounted = <span class="hljs-literal">true</span>
    callHook(vm, <span class="hljs-string">&apos;mounted&apos;</span>)
  }
  <span class="hljs-keyword">return</span> vm
}
</code></pre>
<p>&#x4ECE;&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;<code>mountComponent</code> &#x6838;&#x5FC3;&#x5C31;&#x662F;&#x5148;&#x5B9E;&#x4F8B;&#x5316;&#x4E00;&#x4E2A;&#x6E32;&#x67D3;<code>Watcher</code>&#xFF0C;&#x5728;&#x5B83;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x4E2D;&#x4F1A;&#x8C03;&#x7528; <code>updateComponent</code> &#x65B9;&#x6CD5;&#xFF0C;&#x5728;&#x6B64;&#x65B9;&#x6CD5;&#x4E2D;&#x8C03;&#x7528; <code>vm._render</code> &#x65B9;&#x6CD5;&#x5148;&#x751F;&#x6210;&#x865A;&#x62DF; Node&#xFF0C;&#x6700;&#x7EC8;&#x8C03;&#x7528; <code>vm._update</code> &#x66F4;&#x65B0; DOM&#x3002;</p>
<p><code>Watcher</code> &#x5728;&#x8FD9;&#x91CC;&#x8D77;&#x5230;&#x4E24;&#x4E2A;&#x4F5C;&#x7528;&#xFF0C;&#x4E00;&#x4E2A;&#x662F;&#x521D;&#x59CB;&#x5316;&#x7684;&#x65F6;&#x5019;&#x4F1A;&#x6267;&#x884C;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF0C;&#x53E6;&#x4E00;&#x4E2A;&#x662F;&#x5F53; vm &#x5B9E;&#x4F8B;&#x4E2D;&#x7684;&#x76D1;&#x6D4B;&#x7684;&#x6570;&#x636E;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x7684;&#x65F6;&#x5019;&#x6267;&#x884C;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF0C;&#x8FD9;&#x5757;&#x513F;&#x6211;&#x4EEC;&#x4F1A;&#x5728;&#x4E4B;&#x540E;&#x7684;&#x7AE0;&#x8282;&#x4E2D;&#x4ECB;&#x7ECD;&#x3002;</p>
<p>&#x51FD;&#x6570;&#x6700;&#x540E;&#x5224;&#x65AD;&#x4E3A;&#x6839;&#x8282;&#x70B9;&#x7684;&#x65F6;&#x5019;&#x8BBE;&#x7F6E; <code>vm._isMounted</code> &#x4E3A; <code>true</code>&#xFF0C; &#x8868;&#x793A;&#x8FD9;&#x4E2A;&#x5B9E;&#x4F8B;&#x5DF2;&#x7ECF;&#x6302;&#x8F7D;&#x4E86;&#xFF0C;&#x540C;&#x65F6;&#x6267;&#x884C; <code>mounted</code> &#x94A9;&#x5B50;&#x51FD;&#x6570;&#x3002; &#x8FD9;&#x91CC;&#x6CE8;&#x610F; <code>vm.$vnode</code> &#x8868;&#x793A; Vue &#x5B9E;&#x4F8B;&#x7684;&#x7236;&#x865A;&#x62DF; Node&#xFF0C;&#x6240;&#x4EE5;&#x5B83;&#x4E3A; <code>Null</code> &#x5219;&#x8868;&#x793A;&#x5F53;&#x524D;&#x662F;&#x6839; Vue &#x7684;&#x5B9E;&#x4F8B;&#x3002;</p>
<h2 id="&#x603B;&#x7ED3;">&#x603B;&#x7ED3;</h2>
<p><code>mountComponent</code> &#x65B9;&#x6CD5;&#x7684;&#x903B;&#x8F91;&#x4E5F;&#x662F;&#x975E;&#x5E38;&#x6E05;&#x6670;&#x7684;&#xFF0C;&#x5B83;&#x4F1A;&#x5B8C;&#x6210;&#x6574;&#x4E2A;&#x6E32;&#x67D3;&#x5DE5;&#x4F5C;&#xFF0C;&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x8981;&#x91CD;&#x70B9;&#x5206;&#x6790;&#x5176;&#x4E2D;&#x7684;&#x7EC6;&#x8282;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x6700;&#x6838;&#x5FC3;&#x7684; 2 &#x4E2A;&#x65B9;&#x6CD5;&#xFF1A;<code>vm._render</code> &#x548C; <code>vm._update</code>&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="new-vue.html" class="navigation navigation-prev " aria-label="Previous page: new Vue发生了什么">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="render.html" class="navigation navigation-next " aria-label="Next page: render">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Vue实例挂载的实现","level":"1.3.3","depth":2,"next":{"title":"render","level":"1.3.4","depth":2,"path":"v2/data-driven/render.md","ref":"v2/data-driven/render.md","articles":[]},"previous":{"title":"new Vue发生了什么","level":"1.3.2","depth":2,"path":"v2/data-driven/new-vue.md","ref":"v2/data-driven/new-vue.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"v2/data-driven/mounted.md","mtime":"2021-02-02T00:48:53.870Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-02-02T01:41:31.061Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

